<style type="text/css">
/*优惠券样式*/
    .form-list {
  position: relative;
  background: #fff;
  border-bottom: 1px solid #ddd;
  /*  input::-webkit-input-placeholder{
    color: #333;
  }*/
}
.form-list select,
.form-list input {
  width: 100%;
  border: none;
}
.form-list select {
  padding: 12px 6px;
}
.form-list input {
  padding: 12px 10px;
}
.form-list .triangle {
  border: 6px solid;
  border-color: #000 transparent transparent transparent;
  position: absolute;
  margin-top: -3px;
  right: 10px;
  top: 50%;
}
</style>
<div class="form-box">
	<p class="form-list">
		<select id="mycoupon" name="mycoupon">
			<empty name="coupon">
				<option value="0">暂无优惠券</option>
				<else/>
				<option value="0">请选择优惠券</option>
				<volist name="coupon" id="vol">
					<option value="{BEESCRM:$vol.record_id}" data-value="{BEESCRM:$vol.value}">{BEESCRM:$vol.coupon_title}</option>
				</volist>
			</empty>
		</select>
		<span class="triangle"></span>
	</p>
</div>
<input type="hidden" id="old_money" value="0"/>
<div id="new_money" class="lists text-right">
	<p style="font-size: 14px;">优惠：<span id="money1" style="color: #da2828; ">0元</span></p>
	<p style="font-size: 14px;">合计：<span id="money2" style="color: #da2828;">0元</span></p>
</div>
<script src="/assets/base/water/js/jquery-2.1.0.min.js"></script>
<script language="javascript">
	$(document).on('change','#mycoupon',function(){
		coupon_change_money();
	})

	function coupon_change_money(){
		var old_money = parseFloat($('#old_money').val());
		$('#money1').html('0元');
		$('#money2').html(old_money+'元');
		var value = $("#mycoupon").find("option:selected").data('value');
		if(value > 0 && old_money == 0){
			if(flag == 1){//充电保过来弹框样式不同
				fm.alert('请选择购买的商品或充值金额');return false;
			}else{
				$.alert('error', '请选择购买的商品或充值金额');return false;
			}
			
			$('#mycoupon').val(0);
			return false;
		}

		if(value > 0){
			if(parseFloat(value) >= parseFloat(old_money)){
				if(flag == 1){
					fm.alert('该优惠券不符合使用条件,商品金额不能小于优惠券面额');return false;
				}else{
					$.alert('error', '该优惠券不符合使用条件,商品金额不能小于优惠券面额');
					return false;
				}
			}
			var new_money = parseFloat(old_money - value);
			$('#money1').html(value+'元');
			$('#money2').html(new_money.toFixed(2)+'元');
		}
	}

</script>
